<!--保养历史记录 查询保养完成任务以及保养记录管理-->
<template>
  <div class="dialog">
    <el-dialog
      title="保养处理结果"
      :visible.sync="showDialog"
      width="50%"
      @close="cancel"
      top="0"
    >
      <el-form
        ref="ruleForm"
        label-position="left"
        :model="formData"
        :rules="rules"
        class="el-form"
      >
        <el-form-item label="处理日期：" class="w100p">
          <el-date-picker
            v-model="formData.performStartTime"
            type="datetime"
            placeholder="选择开始时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            clearable
          />
        </el-form-item>
        <el-form-item label="完成度：" class="w100p">
          <el-select
            v-model="formData.whetherFinish"
            clearable
            filterable
            placeholder="请选择完成度"
          >
            <el-option
              v-for="item of finishProcessList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="未完成设备：" class="w100p">
          <el-select
            v-model="formData.whetherFinish"
            clearable
            filterable
            :disabled="!canInput"
            placeholder="请选择未完成设备"
          >
            <el-option
              v-for="item of mixAllEquipmentList"
              :key="item.equipmentCode"
              :label="item.equipmentName"
              :value="item.equipmentCode"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="已选择设备列表" class="w100p">
          <div class="equipment-container">
            <div
              class="equipment-box"
              v-for="(item,index) in checkedEquipmentList"
              :key="index"
            >{{ item.equipmentName }}</div>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { maintenanceMixins } from "@/utils/maintenance-mixins";
export default {
  mixins: [maintenanceMixins],
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    taskId: {
      type: Number,
      default: "",
    },
  },
  data() {
    return {
      formData: {},
      checkedEquipmentList: [],
      equipmentList: [],
      showDialog: this.show,
      canInput: true,
      finishProcessList: [
        {
          id: 0,
          name: "全部完成",
        },
        {
          id: 1,
          name: "部分完成",
        },
      ],
    };
  },
  created() {
    this.mixQueryEquipment();
  },
  watch: {
    show(v) {
      this.showDialog = v;
      if (v) {
        this.queryPageList();
      }
    },
  },
  methods: {
    queryDataItem(item, index) {
      this.activeIndex = index;
      this.checkList = item.taskCheckItemMapperList;
    },
    closeDialog() {
      this.showPictureDialog = false;
    },
    // 查看详情
    queryDetail(row) {
      this.titleText = "";
      this.editObject = row;
      this.showShowDetailDialog = true;
    },
    queryPageList(e) {
      this.loading = true;
      temporaryTaskApi.query({ taskId: this.taskId }).then((res) => {
        this.loading = false;
        if (res.code === 0) {
          this.$message.error("查询失败");
        }
        this.equipmentList = res.data.taskEquipmentMapperList;
        this.checkList =
          res.data.taskEquipmentMapperList[0]?.taskCheckItemMapperList;
      });
    },
    cancel() {
      this.$emit("cancelDialog");
    },
  },
};
</script>
<style scoped lang="scss">
::v-deep {
  .el-dialog {
    min-height: 75vh;
    .el-dialog__body {
      height: 72vh;
    }
  }
  .equipment-container {
    display: flex;
    flex-wrap: wrap;
    .equipment-box {
      width: 24%;
      margin-right: 10px;
    }
  }
}
</style>
